package com.heisenhub.common.oauth.adapter;

import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.io.IOException;
import java.lang.reflect.Type;

public class MyGrantedAuthorityAdapter implements  JsonDeserializer<GrantedAuthority> {

    @Override
    public GrantedAuthority deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        String role = json.getAsJsonObject().get("authority").getAsString();
        // 在这里根据 role 创建并返回相应的 GrantedAuthority 实现类的实例
        // 例如，可以返回一个 SimpleGrantedAuthority 的实例
        return new SimpleGrantedAuthority(role);
    }
}

